<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="id">
                <el-input
                    v-model="queryParams.id"
                    placeholder="请输入id"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="用户ID">
                <el-input
                    v-model="queryParams.userid"
                    placeholder="请输入用户ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="赠送金额">
                <el-input
                    v-model="queryParams.amount"
                    placeholder="请输入赠送金额"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="说明">
                <el-input
                    v-model="queryParams.caseinfo"
                    placeholder="请输入说明"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="可使用金额">
                <el-input
                    v-model="queryParams.available_amount"
                    placeholder="请输入可使用金额"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="手机号">
                <el-input
                    v-model="queryParams.phone"
                    placeholder="请输入手机号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="昵称">
                <el-input
                    v-model="queryParams.nikname"
                    placeholder="请输入昵称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="资金来源">
                <el-select v-model="queryParams.form_type"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in fromTypeOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="创建时间">
                <el-date-picker
                  v-model="dateRange"
                  type="daterange"
                  range-separator="-"
                  start-placeholder="开始日期"
                  value-format="yyyy-MM-dd"
                  style="width:333px;"
                  end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="&nbsp;">
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    plain
                    icon="Download"
                    @click="handleExport"
                    v-hasPermi="['system:gift_money:export']"
                >导出
                </el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="用户ID" align="center" prop="userid"/>
            <el-table-column label="赠送金额" align="center" prop="amount" :formatter="(row) => {return '￥' + row.amount}"/>
            <el-table-column label="说明" align="center" prop="caseinfo"/>
            <el-table-column label="资金来源" align="center" prop="form_type">
                <template slot-scope="{row}">
                    <dict-tag :options="fromTypeOptions" :value="row.form_type" />
                </template>
            </el-table-column>
            <el-table-column label="可使用金额" align="center" prop="available_amount" :formatter="(row) => {return '￥' + row.available_amount}"/>
            <el-table-column label="手机号" align="center" prop="phone"/>
            <el-table-column label="昵称" align="center" prop="nikname" :show-overflow-tooltip="true"/>
            <el-table-column label="头像地址" align="center">
                <template slot-scope="{row}">
                  <el-image
                    v-if="row.avatar"
                    style="width: 40px; height: 40px"
                    :src="row.avatar"
                    :preview-src-list="[row.avatar]">
                  </el-image>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="create_time" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.create_time) }}</span>
                </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

    </div>
</template>

<script>
import * as api from "@/api/finance/gift_money";
export default {
  name: 'GiftMoney',
  components: {  },
  props: {
    uid: {
      type: Number,
      required: true
    },
  },
  data() {
    return {
      list:[],
      loading:true,
      showSearch:false,
      total:0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      fromTypeOptions:[
        { label: '充值送', value: '0' },
        { label: '兑换券', value: '1' },
      ],
    };
  },
  mounted(){
    this.queryParams.userid = this.uid
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      api.listGiftMoney(this.queryParams).then(response => {
          this.list = response.rows || [];
          this.total = response.total || 0;
          this.loading = false;
      });
    },
    handleQuery() {/** 搜索按钮操作 */
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {/** 重置按钮操作 */
      this.dateRange = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.resetForm("queryRef");
      this.handleQuery();
    },
    handleExport() {/** 导出按钮操作 */
      this.download(api.EXPORT_URL, {
          ...this.queryParams.value
      }, `recharge_${new Date().getTime()}.xlsx`);
    },
  }
}

</script>
